package com.sxhnpg.dao;

import java.util.List;


import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.sxhnpg.model.User;

public class UserDao extends BaseDao {

	public Class getEntityClass() {
		return User.class;
	}
	// 用户登录
	public User find(String userid){
		User user=null;
		Session session = getSession();
		if( session != null ){
			Criteria criteria =getSession().createCriteria(getEntityClass());
			criteria.add(Restrictions.eq("userid", userid));
			criteria.add(Restrictions.eq("suspend", 1));
			
			List<User> userList = criteria.list();
			
			if(userList!=null && userList.size()>0) {
				user = userList.get(0);
			}
		}		
		return user;
	}
	
	// 用户登录
	public User findUser(String userid){
		User user=null;
		Session session = getSession();
		if( session != null ){
			Criteria criteria =getSession().createCriteria(getEntityClass());
			criteria.add(Restrictions.eq("userid", userid));
			
			List<User> userList = criteria.list();
			
			if(userList!=null && userList.size()>0) {
				user = userList.get(0);
			}
		}		
		return user;
	}
	
	// 用户列表
	public List<User> findUserList(){
		List<User> userList = null;
		Session session = getSession();
		if( session != null ){
			Criteria criteria =getSession().createCriteria(getEntityClass());
			
			userList = criteria.list();
			
		}		
		return userList;
	}
}
